<?php

namespace Database\Factories;

use App\Commons\Domain\Module\UserCenter\Model\Member;
use Illuminate\Database\Eloquent\Factories\Factory;
use Str;
use Hash;

class MemberFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Member::class;
    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'uid' => $this->faker->uuid,
            'username' => $this->faker->userName,
            'email' => $this->faker->unique()->safeEmail,
            'nickname' => $this->faker->name,
            'mobile' => $this->faker->e164PhoneNumber,
            'avatar' => $this->faker->imageUrl($width = 640, $height = 480),
        ];
    }

    /**
     * 配置模型工厂。
     *
     * @return $this
     */
    public function configure()
    {
        return $this->afterCreating(function (Member $member) {
            $member->account()->create([
                'uid' => $member->uid,
                'username' => $member->username,
                'mobile' => $member->mobile,
                'email' => $member->email,
                'password' => Hash::make('123456'), // password
                'last_logined_at' => now(),
                'last_logined_ip' => $this->faker->ipv4,
                'logined_count' => 1
            ]);
        });
    }
}
